package cn.bby.tools.actions;

import cn.bby.tools.dialog.ParseCsvDialog;
import cn.bby.tools.utils.AnActionEventUtils;
import cn.hutool.core.util.StrUtil;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import org.jetbrains.annotations.NotNull;

/**
 * 解析包含特殊分隔符的CSV文本Action
 * 支持识别特殊字符：x04 x02 x03 0x01作为分隔符
 *
 * @author lingma
 * @version 1.0
 */
public class ParseCsvAction extends AnAction {

    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        String selectedText = AnActionEventUtils.getSelectedText(e);
        if (StrUtil.isEmpty(selectedText)) {
            //获取当前行
            selectedText = AnActionEventUtils.getCurrentLine(e);
        }

        ParseCsvDialog dialog = new ParseCsvDialog(e.getProject(), selectedText);
        dialog.show();
    }
}